extends Resource
class_name CultivationTechnique

# 功法类型枚举
enum TechniqueType {
	FOUNDATION,  # 基础功法
	ELEMENTAL,   # 元素功法
	BODY,        # 炼体功法
	MOVEMENT,    # 身法功法
	ADVANCED     # 高级功法
}

# 基本属性
@export var technique_name: String = "基础功法"
@export var description: String = "一门基础的修炼功法。"
@export var technique_type: int = TechniqueType.FOUNDATION

# 修炼加成
@export var cultivation_speed_bonus: float = 1.0  # 修炼速度加成
@export var spirit_recovery_bonus: float = 1.0    # 真气恢复加成
@export var breakthrough_bonus: float = 1.0       # 突破几率加成

# 功法等级
@export var level: int = 1                        # 当前等级
@export var max_level: int = 9                    # 最大等级

# 功法特性
@export var element_affinity: String = "none"      # 元素亲和
@export var required_realm: int = 0               # 需求境界
@export var required_spirit_root: String = "any"   # 需求灵根
@export var special_effects: Array[String] = []    # 特殊效果

# 属性加成
@export var attack_bonus: int = 0                 # 攻击加成
@export var defense_bonus: int = 0                # 防御加成
@export var speed_bonus: int = 0                  # 速度加成

# 初始化功法
func _init(p_name: String = "", p_type: int = TechniqueType.FOUNDATION) -> void:
	technique_name = p_name if p_name != "" else technique_name
	technique_type = p_type

# 获取当前等级的修炼加成
func get_cultivation_bonus() -> float:
	return cultivation_speed_bonus * (1.0 + (level - 1) * 0.1)

# 获取当前等级的突破加成
func get_breakthrough_bonus() -> float:
	return breakthrough_bonus * (1.0 + (level - 1) * 0.05)

# 检查是否可以修炼（境界和灵根要求）
func can_cultivate(realm: int, spirit_root: String) -> bool:
	if realm < required_realm:
		return false
	if required_spirit_root != "any" and required_spirit_root != spirit_root:
		return false
	return true

# 尝试提升功法等级
func try_level_up() -> bool:
	if level >= max_level:
		return false
	level += 1
	return true
